package com.activenetwork.smlite.testcase.events.createEvents.editEvents;

import java.io.IOException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.activenetwork.custom.uielement.UIElement;
import com.activenetwork.custom.uielement.decorate.IdentifierFactory;
import com.activenetwork.schema.testcase.events.createevents.basics.basics020.Basics020DataType;
import com.activenetwork.smlite.business.EventBusiness;
import com.activenetwork.smlite.business.LoginBusiness;
import com.activenetwork.smlite.page.generic.ModelPage;
import com.activenetwork.smlite.testcase.BaseCase;
import com.activenetwork.util.PageLoader;
import com.activenetwork.util.jaxb.ScriptDataBindHelper;

public class EditEvents001 extends BaseCase {
	static final Logger logger = LoggerFactory.getLogger(EditEvents001.class);
	private EventBusiness eventBusiness = new EventBusiness();
	private Basics020DataType data;
	
	
	@BeforeClass(alwaysRun = true)
	public void dataSetup(){
		try{
			ScriptDataBindHelper helper = new ScriptDataBindHelper(EditEvents001.class);
			data = helper.bind(Basics020DataType.class);
		}catch(IOException e){
			throw new RuntimeException("Unable to bind the script data for " + this.getClass().getName());
		}
	}
	
	@Test
	public void Verify_event_info_loaded_correctly(){
		LoginBusiness loginBusiness = new LoginBusiness(env.getTestEnvironment());
		loginBusiness.login();
		
		// Delete the test event and add it back
		try{
			eventBusiness.deleteEvent(data.getEvent().getBasic().getTitle(), data.getEvent());
		}catch(RuntimeException e){
			logger.info("No need to delete the event since it is not exist");
		}
		
		eventBusiness.addEvent(data.getEvent());
		PageLoader.load(ModelPage.class).events();
		
		eventBusiness.searchEvent(data.getEvent().getBasic().getTitle(), data.getEvent());
		
		
		UIElement e = IdentifierFactory.createUIElement("EventBasicSubview", "eventTitle");
		String value = e.getAttribute("value");
		logger.info(value);
		
		e = IdentifierFactory.createUIElement("EventBasicSubview", "eventCategory");
		value = e.getAttribute("value");
		logger.info(value);
		
		e = IdentifierFactory.createUIElement("EventBasicSubview", "eventDate");
		value = e.getAttribute("value");
		logger.info(value);
		
		e = IdentifierFactory.createUIElement("EventBasicSubview", "startTime");
		value = e.getAttribute("value");
		logger.info(value);
		
	}
}
